package com.baymax.test.scene.demo

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.os.bundleOf
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import androidx.fragment.app.FragmentStatePagerAdapter
import androidx.viewpager.widget.ViewPager
import com.baymax.test.scene.BaseScene

/**
 * @title:       标题
 * @project:     TestScene
 * @package:     com.baymax.test.scene.demo
 * @class:       ViewPagerScene
 * @description:
 * <p>
 * 类描述
 * </p>
 *
 * @version:   1.0
 * @createDate:   2023/3/8 10:16
 * @Copyright (C) 2023 YSTEN
 * @author:       xuyujian
 */
class ViewPagerScene : BaseScene() {
    override fun onCreateView(p0: LayoutInflater, p1: ViewGroup, p2: Bundle?): View {
        return ViewPager(p1.context).apply {
            id = View.generateViewId()
            val fmac = (requireActivity() as FragmentActivity)
            adapter = object : FragmentStatePagerAdapter(fmac.supportFragmentManager) {
                override fun getCount(): Int = 10

                override fun getItem(position: Int): Fragment {
                    return if (position % 2 == 0) {
                        ViewPagerFragmentHolder().apply {
                            arguments = bundleOf("position" to position)
                        }
                    } else {
                        FragmentHolder().apply {
                            arguments = bundleOf("tagStr" to "simple" ,"position" to position)
                        }
                    }

                }

            }
        }
    }
}